# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Arch Haskell Team <arch-haskell@haskell.org>

pkgname=hindent
pkgver=5.3.4
pkgrel=70
pkgdesc="Extensible Haskell pretty printer"
url="https://github.com/mihaimaruseac/hindent"
license=("BSD")
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-monad-loops' 'haskell-optparse-applicative'
         'haskell-path' 'haskell-path-io' 'haskell-src-exts' 'haskell-unix-compat'
         'haskell-utf8-string' 'haskell-yaml')
makedepends=('ghc' 'haskell-diff' 'haskell-hspec')
source=("https://hackage.haskell.org/packages/archive/${pkgname}/${pkgver}/${pkgname}-${pkgver}.tar.gz")
sha512sums=('b6d648c965bde63c19c93505f085e634ff37f5d3a21048aee3e67e42ae4c7238949e49dd14f4c5ba231a748be3996fb7e750764f848b61f3232a8521803fafee')

build() {
    cd $pkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname --enable-tests --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm \
        --ghc-option='-pie'
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

check() {
    cd $pkgname-$pkgver
    runhaskell Setup test --show-details=direct
}

package() {
    cd $pkgname-$pkgver

    install -D -m744 register.sh   "${pkgdir}/usr/share/haskell/register/${pkgname}.sh"
    install -D -m744 unregister.sh "${pkgdir}/usr/share/haskell/unregister/${pkgname}.sh"
    runhaskell Setup copy --destdir="${pkgdir}"
    install -D -m644 LICENSE.md "$pkgdir"/usr/share/licenses/$pkgname/LICENSE.md
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE.md
}
